﻿using MCP.BL;
using System.Web.Mvc;

namespace MoneyCounter.Helpers
{
	public class MessageHelper
	{
		#region Authorization

		/// <summary>
		/// Set custom authentication error message.
		/// </summary>
		/// <param name="controller">Authorization controller.</param>
		/// <param name="message">Message to pass in View.</param>
		/// <param name="errorType">Error type.</param>
		/// <param name="errorPlace">Error place.</param>
		public void SetCustomAuthenticationErrorMessage(Controller controller, string message,
												 AuthenticationResultType errorType, ErrorNotificationPlace errorPlace = ErrorNotificationPlace.General)
		{
			controller.ViewData["LoginErrorMessage"] = message;
			controller.ViewData["LoginErrorType"] = errorType;
			controller.ViewData["NotificationPlace"] = errorPlace;
		}

		/// <summary>
		/// Clears previous authorization errors if any.
		/// </summary>
		/// <param name="controller">Authentication controller.</param>
		public void ClearLogInError(Controller controller)
		{
			controller.ViewData["LoginErrorMessage"] = null;
			controller.ViewData["LoginErrorType"] = null;
			controller.ViewData["NotificationPlace"] = null;
		}

		/// <summary>
		/// Set pre-defined authentication error message.
		/// </summary>
		/// <param name="controller">Authentication controller.</param>
		/// <param name="result">Authentication result.</param>
		/// <param name="errorPlace">Error place.</param>
		public void SetDefaultAuthenticationErrorMessage(Controller controller, AuthenticationResult result)
		{
			controller.ViewData["LoginErrorMessage"] = result.Message;
			controller.ViewData["LoginErrorType"] = result.ResultType;
			controller.ViewData["NotificationPlace"] = result.NotificationPlace;
		}

		#endregion

	}
}